#include "namedPipe.hpp"

// read:管理命名管道生命周期
int main()
{

    NamePiped fifo(comm_path, Creater);
   //对于读端而言，如果打开文件，但是写端没来
   //会阻塞在open调用中，直到对方打开
   //进程同步
    while (true)
    {
        if (fifo.OpenForRead())
        {
            std::cout<<"server open named pipe done"<<std::endl;
            sleep(3);

            std::string message;
            int n = fifo.ReadNamedPipe(&message);
            if (n > 0)
            {
                std::cout << "client say>" << message << std::endl;
            }
            else if(n==0)
            {
                std::cout<<"client quit,server too!"<<std::endl;
                break;
            }
            else
            {
                std::cout<<"fifo.ReadNmaedPipe error"<<std::endl;
                break;
            }
        }
    }

    return 0;
}